package com.example.knowman.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.knowman.ReturnMessage.*;
import com.example.knowman.dao.knowLabelDetailEx;
import com.example.knowman.dao.knowLabelMainEx;
import com.example.knowman.dao.labelCategoryWithStaffNAndKnowCategoryN;
import com.example.knowman.service.IknowLabelDetailService;
import com.example.knowman.service.IlabelCategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//9.2标签
@RestController
@RequestMapping("/knowLabelDetail")
public class KnowLabelDetailController {
    private final IknowLabelDetailService iknowLabelDetailService;

    public KnowLabelDetailController(IknowLabelDetailService iknowLabelDetailService) {
        this.iknowLabelDetailService = iknowLabelDetailService;
    }




    //查
    @GetMapping("getDetails")
    public ResponseEntity<MessageExKnowLabelDetail> getDetails(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                                  @RequestParam Integer knowLblId) {

        IPage<knowLabelDetailEx> res = iknowLabelDetailService.getDetails(pageNum,pageSize,knowLblId);
        MessageExKnowLabelDetail resMessage = new MessageExKnowLabelDetail();
        resMessage.setList(res);
        resMessage.setCode(200);
        resMessage.setTip("查询成功");
        return ResponseEntity.ok(resMessage);

    }

    @GetMapping("Insert")
    public ResponseEntity<MessageBackKnowLabelDetailId> Insert(@RequestParam(required = false) String lblContent,
                                                               @RequestParam(required = false) Integer knowLblId,
                                                               @RequestParam(required = false) Integer labelCateId) {

        MessageBackKnowLabelDetailId res = iknowLabelDetailService.Insert(knowLblId,lblContent,labelCateId);
        if (res.getCode() == 200) {
            return ResponseEntity.ok(res);
        } else {
            return ResponseEntity.badRequest().body(res);
        }
    }

//
//
    //9.1根据单个Id执行删除
    @GetMapping("DeleteByknowLblDtlId")
    public ResponseEntity<Message> DeleteByknowLblDtlId(@RequestParam Integer knowLblDtlId) {

        Message mes  = iknowLabelDetailService.deleteByknowLblDtlId(knowLblDtlId);


        if (mes.getCode() == 200) {
            return ResponseEntity.ok(mes);
        } else {
            return ResponseEntity.badRequest().body(mes);
        }
    }

//


}
